/*
 *   Copyright (C) 2008 - 2009  FireBalls
 *
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

// include
#include "Font.h"

Font *font;

void Font::draw(SDL_Surface *Surf_Window,TTF_Font *font, string str, int x, int y, int r, int g, int b) {

    SDL_Surface *surf;
    SDL_Color color = {r, g, b};
    SDL_Rect rect;

    rect.x = x;
    rect.y = y;

    surf = TTF_RenderText_Solid(font, str.c_str(), color);
    SDL_BlitSurface(surf, NULL, Surf_Window, &rect);

    SDL_FreeSurface(surf);

}

void Font::draw(SDL_Surface *Surf_Window, TTF_Font *font, int i, int x, int y, int r, int g, int b) {
    SDL_Surface *surf;
    SDL_Color color = {r, g, b};
    SDL_Rect rect;
    string str;
    ostringstream stream;

    rect.x = x;
    rect.y = y;
    stream << i;
    str = stream.str();


    surf = TTF_RenderText_Solid(font, str.c_str(), color);
    SDL_BlitSurface(surf, NULL, Surf_Window, &rect);

    SDL_FreeSurface(surf);
}

void Font::draw(SDL_Surface *Surf_Window, TTF_Font *font, double d, int x, int y, int r, int g, int b) {
    SDL_Surface *surf;
    SDL_Color color = {r, g, b};
    SDL_Rect rect;
    string str;
    ostringstream stream;

    rect.x = x;
    rect.y = y;
    stream << d;
    str = stream.str();


    surf = TTF_RenderText_Solid(font, str.c_str(), color);
    SDL_BlitSurface(surf, NULL, Surf_Window, &rect);

    SDL_FreeSurface(surf);
}

void Font::draw(SDL_Surface *Surf_Window, TTF_Font *font, string str, int x, int y) {

    SDL_Surface *surf;
    SDL_Color color = {TextColorR, TextColorG, TextColorB};
    SDL_Rect rect;

    rect.x = x;
    rect.y = y;

    surf = TTF_RenderText_Solid(font, str.c_str(), color);
    SDL_BlitSurface(surf, NULL, Surf_Window, &rect);

    SDL_FreeSurface(surf);

}

void Font::draw(SDL_Surface *Surf_Window, TTF_Font *font, int i, int x, int y) {

    SDL_Surface *surf;
    SDL_Color color = {TextColorR, TextColorG, TextColorB};
    SDL_Rect rect;
    string str;
    ostringstream stream;

    stream << i;
    str = stream.str();
    rect.x = x;
    rect.y = y;

    surf = TTF_RenderText_Solid(font, str.c_str(), color);
    SDL_BlitSurface(surf, NULL, Surf_Window, &rect);

    SDL_FreeSurface(surf);

}

void Font::draw(SDL_Surface *Surf_Window, TTF_Font *font, double d, int x, int y) {

    SDL_Surface *surf;
    SDL_Color color = {TextColorR, TextColorG, TextColorB};
    SDL_Rect rect;
    string str;
    ostringstream stream;

    stream << d;
    str = stream.str();
    rect.x = x;
    rect.y = y;

    surf = TTF_RenderText_Solid(font, str.c_str(), color);
    SDL_BlitSurface(surf, NULL, Surf_Window, &rect);

    SDL_FreeSurface(surf);

}

TTF_Font* Font::load(string path, int size) {

    TTF_Font *font;
    font = TTF_OpenFont(path.c_str(), size);
    if(font == NULL) {
        //Log_Errors << TTF_GetError() << endl;
        Log_Errors.Write(TTF_GetError() + '\n');
    }
    return font;

}

TTF_Font* Font::load(string path) {

    TTF_Font *font;
    font = TTF_OpenFont(path.c_str(), 16);
    if(font == NULL) {
        throw path;
    }
    return font;

}
